﻿<?php
//error_reporting(0);                   关闭php调试警告提示，

$name=$_POST['name'];                  //用post方法对表单提交过来的数据进行处理
$psd=$_POST['psd'];
$link = mysql_connect('localhost', 'root', 'root');                      //连接数据库
mysql_select_db("user",$link);                                      //选择数据库
mysql_query("set names utf8");



$sql = "SELECT * FROM users WHERE name = '$name' and psd ='$psd'"; 
$res = mysql_query($sql); 
$rows=mysql_num_rows($res); 

if($rows){ 

echo "<script language=javascript>open('page-login.html');</script>"; 
setcookie(name,$name , time()+3600);
} elseif($name==''&&$psd==""){
echo"<script type='text/javascript'>alert('请填写用户名密码');history.back();</script>";
return  ;
}         
elseif($name ==''){
echo "<script language=javascript>alert('用户名未填写');history.back();</script>"; 
}elseif($psd == ''){
echo "<script language=javascript>alert('密码未填写');history.back();</script>"; 
}
elseif($name!=='$name' || $psd !== '$psd'){
echo "<script language=javascript>alert('用户名或密码错误');history.back();</script>"; }
               
?>